<?php

class DuploSite extends Duplo {

    public function getDir() {
        return DIR_MODULES.__CLASS__.'/';
    }

    public function defaultAction () {

        $content = new ContentElement();
        $content->run(Duplo::$PARSE_NEXT_PARAM);
        $this->addRequirements($content->getRequirements());

        $pageTemplate = new Template($this->getDir().'index.tpl');
        $pageTemplate->bind('header', $this->formRequirements());
        $pageTemplate->bind('content', $content->getOutput());

        return $pageTemplate->fetch();
    }

    public function errorAction() {
        return $this->defaultAction ();
    }

    private function formRequirements () {
        $header = '';
        $requirements = $this->getRequirements();
        foreach($requirements['css'] as $cssElement) {
			$header .= "\n<link rel='stylesheet' href='{$cssElement}' type='text/css' media='screen' />\n";
        }
		foreach($requirements['js'] as $jsElement) {
			$header .= "\n<script type='text/javascript' src='{$jsElement}'></script>\n";
        }
		return $header;
    }

}
